package com.settlement.system.rules;

import com.googlecode.aviator.AviatorEvaluator;
import com.googlecode.aviator.Expression;
import com.settlement.system.model.entity.SysAudit;
import com.settlement.system.model.entity.SysAuditRule;

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.time.temporal.ChronoUnit;
import java.util.HashMap;
import java.util.Map;

/**
 * 12a、收运费/收差价规则器
 */
public class ReceiveDiffMoneyRuler implements CommonRuler {
    @Override
    public boolean check(SysAudit sysAudit, SysAuditRule auditRule) {
        // "应收账款余额＜0
        //且应收账款余额≥-30（可配置）"
        // 第二个条件
        String expression = "a>=" + auditRule.getReceiveCount();
        Expression compiledExp = AviatorEvaluator.compile(expression);
        Map<String, Object> env = new HashMap<>();
        env.put("a", sysAudit.getReceiveBillAmount());
        boolean billBool = (Boolean) compiledExp.execute(env);
        return billBool &&
                sysAudit.getReceiveBillAmount().compareTo(BigDecimal.ZERO) < 0;
    }
}
